﻿Imports OMANE.Common.UI
Imports System.Collections.ObjectModel
Imports System.Windows
Imports PTIC_Util
Imports PTIC_GestionBDD
Imports System.Windows.Input
Imports OMANE.Common.Model.Interfaces

Namespace ViewModels
    Public Class ViewModelGarantiesDecesPtia
        Inherits ViewModelCommand
        Implements IViewModelTabSection

        Private _model As ModelTauxGarantis
        Public Property IsClosable As Boolean Implements IViewModelTabSection.IsClosable

        Public Sub New(ByVal Model As ModelTauxGarantis, ByVal DisplayName As String, ByVal Command As ICommand)
            MyBase.New(DisplayName, Command)
            _model = Model
            ViewModels.SegmentProvider.model = Model

            _PresenceGarantiePtia = New SegmentableValue(Of Boolean)( _
                AddressOf SegmentCommandNotification, _
                _model.ListeParametres.Pres_GarantiePTIA.Nom, _
                "Présence de la garantie PTIA") With {.Selected = True}
            _MajorationPrudentielle = New SegmentableValue(Of Double)( _
                 AddressOf SegmentCommandNotification, _
                _model.ListeParametres.Tx_Majo_sinDCPTIA.Nom, _
                "Majoration prudentielle des sinistres DC/PTIA")
            _TarifPtia = New SegmentableValue(Of Double)( _
                 AddressOf SegmentCommandNotification, _
                _model.ListeParametres.Tx_PrixGarantiePTIA.Nom, _
                "Tarif Ptia")
            _AgeFinGarantieDecesSegmente = New SegmentableValue(Of Double)( _
                 AddressOf SegmentCommandNotification, _
                _model.ListeParametres.Age_FinDC.Nom, _
                "Age de fin de la garantie DC/PTIA")
            _SelectionMedicale = New SegmentableValueSelMedicale( _
                AddressOf SegmentCommandNotification, _
                _model.ListeParametres.Sel_medic.Nom, _
                "Sélection médicale")


            m_TablesMortaliteFemme = New ObservableCollection(Of IInfoTableReferentiel) _
                ((From elt As IInfoTableReferentiel In _model.Referentiel.InfoTables
                Select elt
                Where elt.TypeTable = "DC").ToList)
            m_TableMortaliteFemmeSelectionne = _
                (From elt As IInfoTableReferentiel In m_TablesMortaliteFemme
                Where elt.NomFichier = _model.ListeParametres.Table_Mortalite_F.ValeurUnique
                Select elt).FirstOrDefault()


            m_TablesMortaliteHomme = New ObservableCollection(Of IInfoTableReferentiel) _
                ((From elt As IInfoTableReferentiel In _model.Referentiel.InfoTables
                Select elt
                Where elt.TypeTable = "DC").ToList)
            m_TableMortaliteHommeSelectionne = _
                (From elt As IInfoTableReferentiel In m_TablesMortaliteHomme
                Where elt.NomFichier = _model.ListeParametres.Table_Mortalite_H.ValeurUnique
                Select elt).FirstOrDefault()

            Title = "GARANTIES DECES/PTIA"
        End Sub
        Sub New()
        End Sub

#Region "TabSection"
        Public Property Icone As String Implements Common.UI.IViewModelTabSection.Icone
        Public Property Title As String Implements Common.UI.IViewModelTabSection.Title
#End Region

#Region "Table de mortalité des hommes"
        Private m_TableMortaliteHommeSelectionne As IInfoTableReferentiel
        Private m_TablesMortaliteHomme As ObservableCollection(Of IInfoTableReferentiel)
        Public Property TableMortaliteHommeSelectionne As IInfoTableReferentiel
            Get
                Return m_TableMortaliteHommeSelectionne
            End Get
            Set(ByVal value As IInfoTableReferentiel)
                OnPropertyChanging("TableMortaliteHommeSelectionne")
                m_TableMortaliteHommeSelectionne = value
                _model.ListeParametres.Table_Mortalite_H.ValeurUnique = m_TableMortaliteHommeSelectionne.NomFichier
                OnPropertyChanged("TableMortaliteHommeSelectionne")
            End Set
        End Property
        Public ReadOnly Property TablesMortaliteHomme As ObservableCollection(Of IInfoTableReferentiel)
            Get
                Return m_TablesMortaliteHomme
            End Get
        End Property
        Public ReadOnly Property TableMortaliteHomme_IsUsed As Boolean
            Get
                Return _model.ListeParametres.Table_Mortalite_H.Methode_Cal(_model.numMethodeCalculEnCours - 1)
            End Get
        End Property
#End Region

#Region "Table de mortalité des femmes"
        Private m_TableMortaliteFemmeSelectionne As IInfoTableReferentiel
        Private m_TablesMortaliteFemme As ObservableCollection(Of IInfoTableReferentiel)
        Public Property TableMortaliteFemmeSelectionne As IInfoTableReferentiel
            Get
                Return m_TableMortaliteFemmeSelectionne
            End Get
            Set(ByVal value As IInfoTableReferentiel)
                OnPropertyChanging("TableMortaliteFemmeSelectionne")
                m_TableMortaliteFemmeSelectionne = value
                _model.ListeParametres.Table_Mortalite_F.ValeurUnique = m_TableMortaliteFemmeSelectionne.NomFichier
                OnPropertyChanged("TableMortaliteFemmeSelectionne")
            End Set
        End Property
        Public ReadOnly Property TablesMortaliteFemme As ObservableCollection(Of IInfoTableReferentiel)
            Get
                Return m_TablesMortaliteFemme
            End Get
        End Property
        Public ReadOnly Property TablesMortaliteFemme_IsUsed As Boolean
            Get
                Return _model.ListeParametres.Table_Mortalite_F.Methode_Cal(_model.numMethodeCalculEnCours - 1)
            End Get
        End Property
#End Region

#Region "Age de fin de la garantie DC"
        Public Property AgeFinGarantieDeces As Integer
            Get
                Return _model.ListeParametres.Age_FinDC.ValeurUnique
            End Get
            Set(ByVal value As Integer)
                OnPropertyChanging("AgeFinGarantieDeces")
                _model.ListeParametres.Age_FinDC.ValeurUnique = value
                OnPropertyChanged("AgeFinGarantieDeces")
            End Set
        End Property
        Public ReadOnly Property AgeFinGarantieDeces_IsUsed As Boolean
            Get
                Return _model.ListeParametres.Age_FinDC.Methode_Cal(_model.numMethodeCalculEnCours - 1)
            End Get
        End Property

        Private _AgeFinGarantieDecesSegmente As SegmentableValue(Of Double)
        Public Property AgeFinGarantieDecesSegmente As SegmentableValue(Of Double)
            Get
                Return _AgeFinGarantieDecesSegmente
            End Get
            Set(ByVal value As SegmentableValue(Of Double))
                OnPropertyChanging("AgeFinGarantieDecesSegmente")
                _AgeFinGarantieDecesSegmente = value
                OnPropertyChanged("AgeFinGarantieDecesSegmente")
            End Set
        End Property
        Public ReadOnly Property AgeFinGarantieDecesSegmente_IsUsed As Boolean
            Get
                Return _model.ListeParametres.Age_FinDC.Methode_Cal(_model.numMethodeCalculEnCours - 1)
            End Get
        End Property
#End Region

#Region "Tarif de fin de la garantie Ptia"
        Private _TarifPtia As SegmentableValue(Of Double)
        Public Property TarifPtia As SegmentableValue(Of Double)
            Get
                Return _TarifPtia
            End Get
            Set(ByVal value As SegmentableValue(Of Double))
                OnPropertyChanging("TarifPtia")
                _TarifPtia = value
                OnPropertyChanged("TarifPtia")
            End Set
        End Property
        Public ReadOnly Property tarifPTIA_IsUsed As Boolean
            Get
                Return _model.ListeParametres.Tx_PrixGarantiePTIA.Methode_Cal(_model.numMethodeCalculEnCours - 1)
            End Get
        End Property
#End Region

#Region "Présence de la garantie Ptia"
        Private _PresenceGarantiePtia As SegmentableValue(Of Boolean)
        Public Property PresenceGarantiePtia As SegmentableValue(Of Boolean)
            Get
                Return _PresenceGarantiePtia
            End Get
            Set(ByVal value As SegmentableValue(Of Boolean))
                OnPropertyChanging("PresenceGarantiePtia")
                _PresenceGarantiePtia = value
                OnPropertyChanged("PresenceGarantiePtia")
            End Set
        End Property
        Public ReadOnly Property PresenceGarantiePTIA_IsUsed As Boolean
            Get
                Return _model.ListeParametres.Pres_GarantiePTIA.Methode_Cal(_model.numMethodeCalculEnCours - 1)
            End Get
        End Property
#End Region

#Region "Majoration prudentielle (marge technique) des sinistres DC"
        Private _MajorationPrudentielle As SegmentableValue(Of Double)
        Public Property MajorationPrudentielle As SegmentableValue(Of Double)
            Get
                Return _MajorationPrudentielle
            End Get
            Set(ByVal value As SegmentableValue(Of Double))
                OnPropertyChanging("MajorationPrudentielle")
                _MajorationPrudentielle = value
                OnPropertyChanged("MajorationPrudentielle")
            End Set
        End Property
        Public ReadOnly Property MajorationPrudentielle_IsUsed As Boolean
            Get
                Return _model.ListeParametres.Tx_Majo_sinDCPTIA.Methode_Cal(_model.numMethodeCalculEnCours - 1)
            End Get
        End Property
#End Region

#Region "Sélection médicale"
        Private _SelectionMedicale As SegmentableValueSelMedicale
        Public Property SelectionMedicale As SegmentableValueSelMedicale
            Get
                Return _SelectionMedicale
            End Get
            Set(ByVal value As SegmentableValueSelMedicale)
                OnPropertyChanging("SelectionMedicale")
                _SelectionMedicale = value
                OnPropertyChanged("SelectionMedicale")
            End Set
        End Property
        Public ReadOnly Property SelectionMedicale_IsUsed As Boolean
            Get
                'Return _model.Univers.ListeParametres.Sel_medic.Methode_Cal(_model.Univers.numMethodeCalculEnCours - 1)
                Return True
            End Get
        End Property
#End Region

#Region "Segment"
        Private _CurrentSegmentableValue As Object
        Public Property CurrentSegmentableValue As Object
            Get
                Return _CurrentSegmentableValue
            End Get
            Set(ByVal value As Object)
                OnPropertyChanging("CurrentSegmentableValue")
                _CurrentSegmentableValue = value
                OnPropertyChanged("CurrentSegmentableValue")
            End Set
        End Property

        Private Sub SegmentCommandNotification(ByVal sender As Object, ByVal param As Object)
            CurrentSegmentableValue = sender
        End Sub
#End Region

      

        'Public Sub exempleModifSegmentation(ByVal nomColonne As String, ByVal nomParametre As String)

        '    'Pour DC et INCAP/INVAL
        '    Dim reqParam As RequeteBDD = _model.Univers.listeTraitements.TraitReqSegmentationParam(nomParametre)
        '    'For Each draggedItem As ListViewItem In draggedItems
        '    reqParam.addSELECT(_model.Univers.listeTraitements.TraitTbleEncoursPrep1.nom, nomColonne)
        '    'Next
        '    Dim d As DataTable
        '    reqParam.Calculer_DataTable()
        '    d = reqParam.DataTableResultat

        '    'Ajouter une colonne pour les valeurs (nom de la colonne = nom du paramètre)
        '    Dim n As String = Actuariat.csteParam.nomTx_CommiContA
        '    'Renseigner par défaut toutes les valeurs de la nouvelle colonne.


        '    _model.Parametres.Tx_TechA.SetValeursDataTable(d)
        'End Sub

        'Public Sub listeSegmentPossibles()
        '    Dim l As ObservableDictionary(Of String, Correspondance) = _model.Univers.Segmentation.PossibleNonRetenue
        '    For Each a In l.Values
        '        Dim b As String = a.description
        '        Dim c As Type = a.GetType
        '    Next
        'End Sub
        'Private Sub RecupereTableVariableDisponibles()
        '    'Dim a As ObservableDictionary(Of String, Correspondance) = _model.Univers.ListeParametres(<nomParametre>).GetSegmentsPossibles
        '    'Dim tble As DataTable = _model.Univers.ListeParametres(<nomParametre>).GetValeur
        'End Sub

    End Class
End Namespace



Public Class Pair
    Inherits DependencyObject

    Public Property Left As Boolean
        Get
            Return GetValue(LeftProperty)
        End Get

        Set(ByVal value As Boolean)
            SetValue(LeftProperty, value)
        End Set
    End Property

    Public Shared ReadOnly LeftProperty As DependencyProperty = _
                           DependencyProperty.Register("Left", _
                           GetType(Boolean), GetType(Pair), _
                           New FrameworkPropertyMetadata(Nothing))



    Public Property Right As String
        Get
            Return GetValue(RightProperty)
        End Get

        Set(ByVal value As String)
            SetValue(RightProperty, value)
        End Set
    End Property

    Public Shared ReadOnly RightProperty As DependencyProperty = _
                           DependencyProperty.Register("Right", _
                           GetType(String), GetType(Pair), _
                           New FrameworkPropertyMetadata(Nothing))




End Class
